#!/usr/bin/make -f -

# use emacs as a shell, so that we can write emacs lisp code in here
SHELL := emacs
# set some flags for emacs
.SHELLFLAGS := --quick --batch --eval

# all org mode files will be converted
# orgs := $(wildcard *.org)
# only the list.org file will be converted
orgs := list.org
objs := $(orgs:.org=.md) $(orgs:.org=.texi) $(orgs:.org=.html)

.PHONY: all
all: $(objs)

.PHONY: clean
clean:
	/bin/rm --verbose *.html *.md *.texi || true;

# in here comes the shell specific code
.ONESHELL:
%.html %.md %.texi: %.org
	(with-temp-buffer
	  (require 'ox-md)
	  (require 'ox-texinfo)
	  (require 'ox-html)
	  (when (insert-file-contents "$<")
		(org-mode)
		(org-export-to-file 'md "$*.md")
		(org-export-to-file 'texinfo "$*.texi")
		(org-export-to-file 'html "$*.html")))
